package com.itheima.reggie.controller;

import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Category;
import com.itheima.reggie.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apiguardian.api.API;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

// 菜品分类模块
@Api(tags = "菜品分类模块")
@RestController
public class CategoryController {

    @Autowired
    private CategoryService categoryService;
    // 查询所有
    @GetMapping("/category/findAll")
    @ApiOperation(value = "查询所有")
    public ResultInfo findAll(){
        // 接受请求参数 然后调用service的方法
        List<Category> categoryList=categoryService.findAll();
        // 返回结果
        return ResultInfo.success(categoryList);
    }


    // 新增
    @PostMapping("/category")
    @ApiOperation(value = "新增")
    @ApiImplicitParams({
            @ApiImplicitParam(name ="category",value = "对象",required = true)
    })
    public ResultInfo save(@RequestBody Category category){// 接受请求
        // 调用service 的新增
        categoryService.save(category);
        // 返回结果
        return ResultInfo.success();
    }

    // 修改
    @PutMapping("/category")
    @ApiOperation(value = "修改")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name ="category",value = "要修改的对象",required = true)
            }
    )
    public ResultInfo updateById(@RequestBody Category category){// 接收参数
        // 调用service的修改方法
        categoryService.updateById(category);
        // 返回结果
        return ResultInfo.success();
    }

    // 删除
    @DeleteMapping("/category")
    @ApiOperation("删除")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "要删除的类型id",required = true)
    })
    public ResultInfo delete(Long id){

        // 调用service 删除
        ResultInfo resultInfo=categoryService.delete(id);
        // 返回结果
        return resultInfo;
    }
    // 新增菜品回显菜系
    @GetMapping("/category/list") // 他是？传参所以不用注释接收参数
    @ApiOperation("菜品回显")
    @ApiImplicitParam(name = "type",value = "回显类型",required = true)
    public ResultInfo findByType(Integer type){ //接收参数
        // 调用category层的查询菜系
    List<Category> categoryList=categoryService.findByType(type);
    // 返回一个集合
    return ResultInfo.success(categoryList);
    }

}
